//
//  LGAddSchedulController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/28.
//  添加排班

#import "LGAddSchedulController.h"

#import "LGLineTitleTipView.h"

#import "LGCustomTextView.h"
#import "LGPickerView.h"

#define item_W   viewPix(32)
@interface LGAddSchedulController ()
/**  星期 */
@property (nonatomic , strong)UIView *weekView;
/**   */
@property (nonatomic , strong)UILabel *weekTitle;
/**   */
@property (nonatomic , strong)UIButton *weekBtn1;
/**   */
@property (nonatomic , strong)UIButton *weekBtn2;
/**   */
@property (nonatomic , strong)UIButton *weekBtn3;
/**   */
@property (nonatomic , strong)UIButton *weekBtn4;
/**   */
@property (nonatomic , strong)UIButton *weekBtn5;
/**   */
@property (nonatomic , strong)UIButton *weekBtn6;
/**   */
@property (nonatomic , strong)UIButton *weekBtn7;

/**  时间段 */
@property (nonatomic , strong)UIView *timeView;
/**   */
@property (nonatomic , strong)UILabel *timeTitle;
/**   */
@property (nonatomic , strong)UIView *timeBtnView;
/**   */
@property (nonatomic , strong)UIButton *amButton;
/**   */
@property (nonatomic , strong)UIButton *pmButton;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *startView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *endView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *spaceView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *numberView;

/**  接诊院区、诊室 */
@property (nonatomic , strong)UIView *locationView;
@property (nonatomic , strong)LGLineTitleTipView *hospitalView;
@property (nonatomic , strong)LGLineTitleTipView *roomView;
@property (nonatomic , strong)UITextField *roomTF;

/**  删除、重置 */
@property (nonatomic , strong)UIButton *leftButton;
/**   */
@property (nonatomic , strong)UIButton *sureButton;
/**   */
@property (nonatomic , assign)CGFloat weekMargin;
/**   */
@property (nonatomic , assign)NSInteger space;
/**   */
@property (nonatomic , strong)NSMutableArray *weekArray;

/**   */
@property (nonatomic , strong)NSArray *hospitalArray;

@end

@implementation LGAddSchedulController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.‘
    self.space = 15;
    self.title = @"添加排班";
    self.weekMargin = (Screen_W-viewPix(54)-item_W*7)/6.0;
    [self createSubView];
    if(_scheduleids && _scheduleids.length>0){
        [self requestSchedulDetail];
    }
    if (_type && [_type isEqualToString:@"1"]) {
        self.locationView.hidden = NO;
    }else{
        self.locationView.hidden = YES;
    }
    [self requestHospitalData];
}

-(void)setScheduleIds:(NSArray *)scheduleIds{
    _scheduleIds = scheduleIds;
    NSString *result = @"";
    for (NSInteger i=0; i<scheduleIds.count; i++) {
        result = (result.length>0)?[NSString stringWithFormat:@"%@,%@",result,scheduleIds[i]]:[NSString stringWithFormat:@"%@",scheduleIds[i]];
    }
    self.scheduleids = result;
}

-(void)requestHospitalData{
    [RequestUtil withPOST:@"/doctor/visit.Visit/compoundSelect" parameters:@{} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            NSArray *tempArray = returnData;
            NSMutableArray *nameArray = [NSMutableArray array];
            for (NSDictionary *tempDic in tempArray) {
                [nameArray addObject:LGNSString(tempDic[@"name"])];
            }
            self.hospitalArray = nameArray;
            self.hospitalView.hidden = (self.hospitalArray.count>1)?NO:YES;
            CGFloat baseHeight = (self.hospitalArray.count>1)?viewPix(106):viewPix(53);
            self.locationView.frame = CGRectMake(viewPix(16), kMaxY(self.timeView.frame)+viewPix(16), Screen_W-viewPix(32), baseHeight);
        }
    } error:^(NSError *error) {
        
    }];
}

-(void)requestSchedulDetail{
    [RequestUtil withPOST:@"/doctor/visit.Visit/scheduleDetail" parameters:@{@"schedule_ids":self.scheduleids} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            NSDictionary *tempDic = returnData;
            self.space = [tempDic[@"duration"] integerValue]/60;
            NSArray *times = [LGNSString(tempDic[@"time"]) componentsSeparatedByString:@"-"];
            if(times.count>1){
                self.startView.content = times[0];
                self.endView.content = times[1];
            }
            NSArray *weeks = tempDic[@"week_days"];
            self.weekArray = [NSMutableArray arrayWithArray:weeks];
            for (NSInteger i=0; i<weeks.count; i++) {
                UIButton *button = [self.view viewWithTag:1000+[weeks[i] integerValue]];
                button.selected = YES;
            }
            
            if([tempDic[@"period"] integerValue] == 1){
                self.amButton.selected = YES;
                self.pmButton.selected = NO;
            }else{
                self.amButton.selected = NO;
                self.pmButton.selected = YES;
            }
            
            self.numberView.content = [NSString stringWithFormat:@"%@ 人",tempDic[@"total"]];
            self.hospitalView.content = [LGNSString(tempDic[@"compound"]) isEmptyString]?@"":LGNSString(tempDic[@"compound"]);
            self.roomTF.text = LGNSString(tempDic[@"visit_address"]);
        }
    } error:^(NSError *error) {
        
    }];
}

-(void)setSpace:(NSInteger)space{
    _space = space;
    self.spaceView.content = [NSString stringWithFormat:@"%ld 分钟/人",self.space];
    [self caculateTimeCorrect:self.startView.content endTime:self.endView.content];
}

//星期一 -- 日
-(void)weekBtnTouchAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    if(sender.selected == YES){
        [self.weekArray addObject:@(sender.tag-1000)];
    }else{
        [self.weekArray removeObject:@(sender.tag-1000)];
    }
}

//上午 、 下午
-(void)timeButtonTouchAction:(UIButton *)sender{
    if(sender == self.amButton){
        self.amButton.selected = YES;
        self.pmButton.selected = NO;
        
    }else{
        self.amButton.selected = NO;
        self.pmButton.selected = YES;
    }
    self.startView.content = @"";
    self.endView.content = @"";
    self.numberView.content = @"0 人";
}

//选择时间
-(void)selectTimeAction:(UITapGestureRecognizer *)sender{
    [self.roomTF resignFirstResponder];
    CGPoint point = [sender locationInView:self.timeView];
    if(point.y<viewPix(59)) return;

    if(CGRectContainsPoint(self.spaceView.frame, point)){
        //号源间隔
        NSArray *spaceArray = @[@"5",@"10",@"15",@"20",@"30",@"40",@"50",@"60"];
        LGPickerView *pickView = [[LGPickerView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
        pickView.titleLabel.text = @"时间间隔";
        pickView.pickArry = @[spaceArray];
        pickView.units = @[@"分钟"];
        pickView.selectStr = [NSString stringWithFormat:@"%ld",self.space];
        [self.view.window addSubview:pickView];
        __weak typeof(self) weakSelf = self;
        pickView.selectPickViewResult = ^(NSArray *resultArray) {
            NSString *result = LGNSString(resultArray[0]);
            if([result integerValue] != self.space){
                weakSelf.space = [result integerValue];
            }
        };
       
    }else if(CGRectContainsPoint(self.startView.frame, point) || CGRectContainsPoint(self.endView.frame, point)){
        //开始、结束时间
        NSArray *hourArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11"];
        if(self.pmButton.selected == YES){
            hourArray = @[@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23"];
        }
        NSString *selectStr = @"";
        NSMutableArray *miniArray = [NSMutableArray array];
        NSInteger currentNum = 0;
        for (NSInteger i = 0; i<12; i++) {
            NSString *time = [NSString stringWithFormat:@"%.2ld",currentNum];
            [miniArray addObject:time];
            currentNum += 5;
        }
        NSString *midleMinit = miniArray[6];
        NSString *title = @"";
        if(CGRectContainsPoint(self.startView.frame, point)){
            //开始时间
            title = @"开始时间";
            if(self.startView.content.length>0){
                selectStr = [self.startView.content stringByReplacingOccurrencesOfString:@":" withString:@"|"];
            }else{
                selectStr = (self.amButton.selected == YES)?[NSString stringWithFormat:@"08|%@",midleMinit]:[NSString stringWithFormat:@"13|%@",midleMinit];
            }
        }else{
            //结束时间
            title = @"结束时间";
            if(self.endView.content.length>0){
                selectStr = [self.endView.content stringByReplacingOccurrencesOfString:@":" withString:@"|"];
            }else{
                selectStr = (self.amButton.selected == YES)?[NSString stringWithFormat:@"11|%@",midleMinit]:[NSString stringWithFormat:@"17|%@",midleMinit];
            }
        }
        
        LGPickerView *pickView = [[LGPickerView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
        pickView.titleLabel.text = title;
        pickView.pickArry = @[hourArray , miniArray];
        pickView.selectStr = selectStr;
        [self.view.window addSubview:pickView];
        __weak typeof(self) weakSelf = self;
        pickView.selectPickViewResult = ^(NSArray *resultArray) {
            NSString *timeString = [NSString stringWithFormat:@"%@:%@",resultArray[0],resultArray[1]];
            if(CGRectContainsPoint(self.startView.frame, point)){
                if([self caculateTimeCorrect:timeString endTime:self.endView.content] == YES){
                    weakSelf.startView.content = timeString;
                    return;
                }
            }else{
                if([self caculateTimeCorrect:self.startView.content endTime:timeString] == YES){
                    weakSelf.endView.content = timeString;
                    return;
                }
            }
            [TooltipView showMessage:@"结束时间不能早于开始时间" offset:0];
        };
    }
}

-(BOOL)caculateTimeCorrect:(NSString *)startTime  endTime:(NSString *)endTime{
    BOOL result = YES;
    if(startTime.length>0 && endTime.length>0){
        NSArray *startArray = [startTime componentsSeparatedByString:@":"];
        NSArray *endArray = [endTime componentsSeparatedByString:@":"];
        NSInteger startHour = [startArray[0] integerValue];
        NSInteger startMini = [startArray[1] integerValue];
        NSInteger endHour = [endArray[0] integerValue];
        NSInteger endMini = [endArray[1] integerValue];
        if(startHour>endHour){
            result = NO;
        }else if (startHour == endHour && startMini>=endMini){
            result = NO;
        }else{
            NSInteger minite = (endHour-startHour)*60+endMini-startMini;
            CGFloat number = (CGFloat)minite/self.space;
            self.numberView.content = [NSString stringWithFormat:@"%ld 人",minite/self.space];
        }
    }
    
    return result;
}

//选择接诊院区
-(void)selectHospitalAction{
    if (self.hospitalArray.count>1) {
        LGPickerView *pickerView = [[LGPickerView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
        pickerView.selectStr = self.hospitalView.content;
        pickerView.pickArry = @[self.hospitalArray];
        [[ObjectTool mainWindow] addSubview:pickerView];
        __weak typeof(self) weakSelf = self;
        pickerView.selectPickViewResult = ^(NSArray *resultArray) {
            weakSelf.hospitalView.content = LGNSString(resultArray[0]);
        };
    }else{
        [self requestHospitalData];
    }
}

//删除
-(void)leftButtonAction{
    [RequestUtil withPOST:@"/doctor/visit.Visit/scheduleDelete" parameters:@{@"schedule_ids":self.scheduleids} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            [TooltipView showMessage:@"删除成功" offset:0];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [TooltipView showMessage:message offset:0];
        }
    } error:^(NSError *error) {
        [TooltipView showMessage:LGErrorMessage offset:0];
    }];
}

//确定
-(void)sureButtonAction{
    if(self.weekArray.count == 0){
        [TooltipView showMessage:@"请先选择星期" offset:0];
    }else if (self.startView.content.length == 0){
        [TooltipView showMessage:@"请选择开始时间" offset:0];
    }else if (self.endView.content.length == 0){
        [TooltipView showMessage:@"请选择结束时间" offset:0];
    }else{
        NSString *weeks = @"";
        for (NSInteger i=0; i<self.weekArray.count; i++) {
            weeks = (weeks.length == 0)?[NSString stringWithFormat:@"%@",self.weekArray[i]]:[NSString stringWithFormat:@"%@,%@",weeks,self.weekArray[i]];
        }
        
        NSString *period = (self.amButton.selected == YES)?@"1":@"3";
        NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"clinic_type":self.type , @"period":period , @"week_days":weeks , @"start_time":self.startView.content , @"end_time":self.endView.content,@"duration":[NSString stringWithFormat:@"%ld",self.space*60]}];
        if(_scheduleids && _scheduleids.length>0){
            [parameters setValue:self.scheduleids forKey:@"schedule_ids"];
        }
        if ([self.type isEqualToString:@"1"]) {
            //线下复查 -- 要加 visit_address
            if (self.hospitalView.content.length == 0 && self.hospitalArray.count>1) {
                [TooltipView showMessage:@"请选择复查院区" offset:0];
                return;
            }
            NSString *compound = self.hospitalView.content.length>0?self.hospitalView.content:@"";
            NSString *roomText = self.roomTF.text.length>0?self.roomTF.text:@"";
            [parameters setValue:compound forKey:@"compound"];
            [parameters setValue:roomText forKey:@"visit_address"];
        }
        [RequestUtil withPOST:@"/doctor/visit.Visit/saveSchedule" parameters:parameters withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
            if(code == 200){
                [TooltipView showMessage:@"保存成功" offset:0];
                [self.navigationController popViewControllerAnimated:YES];
            }else{
                [TooltipView showMessage:message offset:0];
            }
        } error:^(NSError *error) {
            
        }];
    }
}



#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.view addSubview:self.weekView];
    [self.weekView addSubview:self.weekTitle];
    [self.weekView addSubview:self.weekBtn1];
    [self.weekView addSubview:self.weekBtn2];
    [self.weekView addSubview:self.weekBtn3];
    [self.weekView addSubview:self.weekBtn4];
    [self.weekView addSubview:self.weekBtn5];
    [self.weekView addSubview:self.weekBtn6];
    [self.weekView addSubview:self.weekBtn7];
    [self.view addSubview:self.timeView];
    [self.timeView addSubview:self.timeTitle];
    [self.timeView addSubview:self.timeBtnView];
    [self.timeBtnView addSubview:self.amButton];
    [self.timeBtnView addSubview:self.pmButton];
    [self.timeView addSubview:self.startView];
    [self.timeView addSubview:self.endView];
    [self.timeView addSubview:self.spaceView];
    [self.timeView addSubview:self.numberView];

    [self.view addSubview:self.locationView];
    [self.locationView addSubview:self.hospitalView];
    [self.locationView addSubview:self.roomView];
    [self.roomView addSubview:self.roomTF];
    
    [self.roomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.locationView).offset(-viewPix(6));
        make.left.right.height.equalTo(self.hospitalView);
    }];
    [self.view addSubview:self.sureButton];
    if(_scheduleids && _scheduleids.length>0){
        self.sureButton.frame = CGRectMake(kMaxX(self.leftButton.frame)+viewPix(12), kMinY(self.leftButton.frame), (Screen_W-viewPix(44))/2.0, viewPix(46));
        [self.view addSubview:self.leftButton];
    }
}

-(NSMutableArray *)weekArray{
    if(!_weekArray){
        _weekArray = [NSMutableArray array];
    }
    return _weekArray;
}

-(UIView *)weekView{
    if(!_weekView){
        _weekView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(32), viewPix(94))];
        [_weekView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _weekView.backgroundColor = [UIColor whiteColor];
    }
    return _weekView;
}

-(UILabel *)weekTitle{
    if(!_weekTitle){
        _weekTitle = [UILabel lableWithText:@"星期" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _weekTitle.frame = CGRectMake(viewPix(12), viewPix(16), viewPix(60), viewPix(22));
    }
    return _weekTitle;
}

-(UIButton *)weekBtn1{
    if(!_weekBtn1){
        _weekBtn1 = [UIButton buttonWithTitle:@"日" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn1.frame = CGRectMake(viewPix(10), kMaxY(self.weekTitle.frame)+viewPix(8), item_W, item_W);
        [_weekBtn1 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn1 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn1.cornerRidus = item_W/2.0;
        _weekBtn1.tag = 1000+0;
        [_weekBtn1 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn1;
}

-(UIButton *)weekBtn2{
    if(!_weekBtn2){
        _weekBtn2 = [UIButton buttonWithTitle:@"一" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn2.frame = CGRectMake(kMaxX(self.weekBtn1.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn2 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn2 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn2.cornerRidus = item_W/2.0;
        _weekBtn2.tag = 1000+1;
        [_weekBtn2 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn2;
}

-(UIButton *)weekBtn3{
    if(!_weekBtn3){
        _weekBtn3 = [UIButton buttonWithTitle:@"二" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn3.frame = CGRectMake(kMaxX(self.weekBtn2.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn3 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn3 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn3.cornerRidus = item_W/2.0;
        _weekBtn3.tag = 1000+2;
        [_weekBtn3 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn3;
}

-(UIButton *)weekBtn4{
    if(!_weekBtn4){
        _weekBtn4 = [UIButton buttonWithTitle:@"三" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn4.frame = CGRectMake(kMaxX(self.weekBtn3.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn4 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn4 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn4.cornerRidus = item_W/2.0;
        _weekBtn4.tag = 1000+3;
        [_weekBtn4 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn4;
}

-(UIButton *)weekBtn5{
    if(!_weekBtn5){
        _weekBtn5 = [UIButton buttonWithTitle:@"四" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn5.frame = CGRectMake(kMaxX(self.weekBtn4.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn5 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn5 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn5.cornerRidus = item_W/2.0;
        _weekBtn5.tag = 1000+4;
        [_weekBtn5 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn5;
}

-(UIButton *)weekBtn6{
    if(!_weekBtn6){
        _weekBtn6 = [UIButton buttonWithTitle:@"五" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn6.frame = CGRectMake(kMaxX(self.weekBtn5.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn6 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn6 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn6.cornerRidus = item_W/2.0;
        _weekBtn6.tag = 1000+5;
        [_weekBtn6 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn6;
}

-(UIButton *)weekBtn7{
    if(!_weekBtn7){
        _weekBtn7 = [UIButton buttonWithTitle:@"六" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn7.frame = CGRectMake(kMaxX(self.weekBtn6.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn7 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn7 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn7.cornerRidus = item_W/2.0;
        _weekBtn7.tag = 1000+6;
        [_weekBtn7 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn7;
}

-(UIView *)timeView{
    if(!_timeView){
        _timeView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.weekView.frame)+viewPix(16), Screen_W-viewPix(32), viewPix(252))];
        [_timeView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _timeView.backgroundColor = [UIColor whiteColor];
        [_timeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectTimeAction:)]];
    }
    return _timeView;
}

-(UILabel *)timeTitle{
    if(!_timeTitle){
        _timeTitle = [UILabel lableWithText:@"时间段" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _timeTitle.frame = CGRectMake(viewPix(15), viewPix(26), viewPix(60), viewPix(20));
    }
    return _timeTitle;
}

-(UIView *)timeBtnView{
    if(!_timeBtnView){
        _timeBtnView = [[UIView alloc]initWithFrame:CGRectMake(Screen_W-viewPix(48)-viewPix(164), viewPix(18), viewPix(164), viewPix(36))];
        _timeBtnView.backgroundColor = [UIColor colorWithString:@"#F7F7F7"];
        _timeBtnView.cornerRidus = viewPix(18);
    }
    return _timeBtnView;
}

-(UIButton *)amButton{
    if(!_amButton){
        _amButton = [UIButton buttonWithTitle:@"上午" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#61616D" selectColor:@"#FFFFFF"];
        [_amButton setBackgroundColor:[UIColor colorWithString:@"#F7F7F7"] forState:UIControlStateNormal];
        [_amButton setBackgroundColor:[UIColor colorWithString:@"#3291FF"] forState:UIControlStateSelected];
        _amButton.frame = CGRectMake(0, 0, viewPix(82), viewPix(36));
        _amButton.cornerRidus = viewPix(18);
        _amButton.selected = YES;
        [_amButton addTarget:self action:@selector(timeButtonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _amButton;
}

-(UIButton *)pmButton{
    if(!_pmButton){
        _pmButton = [UIButton buttonWithTitle:@"下午" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#61616D" selectColor:@"#FFFFFF"];
        [_pmButton setBackgroundColor:[UIColor colorWithString:@"#F7F7F7"] forState:UIControlStateNormal];
        [_pmButton setBackgroundColor:[UIColor colorWithString:@"#3291FF"] forState:UIControlStateSelected];
        _pmButton.frame = CGRectMake(viewPix(82), 0, viewPix(82), viewPix(36));
        _pmButton.cornerRidus = viewPix(18);
        [_pmButton addTarget:self action:@selector(timeButtonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _pmButton;
}

-(LGLineTitleTipView *)startView{
    if(!_startView){
        _startView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, viewPix(59), Screen_W-viewPix(32), viewPix(47))];
        _startView.lineView.hidden = YES;
        _startView.title = @"开始时间";
        _startView.type = @"text";
    }
    return _startView;
}

-(LGLineTitleTipView *)endView{
    if(!_endView){
        _endView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.startView.frame), Screen_W-viewPix(32), viewPix(47))];
        _endView.lineView.hidden = YES;
        _endView.title = @"结束时间";
        _endView.type = @"text";
    }
    return _endView;
}

-(LGLineTitleTipView *)spaceView{
    if(!_spaceView){
        _spaceView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.endView.frame), Screen_W-viewPix(32), viewPix(47))];
        _spaceView.lineView.hidden = YES;
        _spaceView.title = @"时间间隔";
        _spaceView.type = @"text";
    }
    return _spaceView;
}

-(LGLineTitleTipView *)numberView{
    if(!_numberView){
        _numberView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.spaceView.frame), Screen_W-viewPix(32), viewPix(47))];
        _numberView.lineView.hidden = YES;
        _numberView.title = @"每日接诊人数上限";
        _numberView.content = @"0 人";
        _numberView.type = @"text";
        [_numberView.tipView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(0));
        }];
    }
    return _numberView;
}

-(UIView *)locationView{
    if(!_locationView){
        _locationView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.timeView.frame)+viewPix(16), Screen_W-viewPix(32), viewPix(106))];
        [_locationView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _locationView.backgroundColor = [UIColor whiteColor];
    }
    return _locationView;
}

-(LGLineTitleTipView *)hospitalView{
    if(!_hospitalView){
        _hospitalView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, viewPix(6), Screen_W-viewPix(32), viewPix(47))];
        _hospitalView.lineView.hidden = YES;
        _hospitalView.title = @"接诊院区";
        _hospitalView.type = @"text";
        [_hospitalView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectHospitalAction)]];
    }
    return _hospitalView;
}

-(LGLineTitleTipView *)roomView{
    if(!_roomView){
        _roomView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.hospitalView.frame), Screen_W-viewPix(32), viewPix(47))];
        _roomView.lineView.hidden = YES;
        _roomView.title = @"接诊诊室";
        _roomView.type = @"text";
        _roomView.content = @" ";
        [_roomView.tipView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(0));
        }];
    }
    return _roomView;
}

-(UITextField *)roomTF{
    if(!_roomTF){
        _roomTF = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(80), 0, Screen_W-viewPix(130), viewPix(47))];
        _roomTF.tintColor = [UIColor colorWithString:@"#606266"];
        _roomTF.textColor = [UIColor colorWithString:@"#606266"];
        _roomTF.textAlignment = NSTextAlignmentRight;
        _roomTF.keyboardType = UIKeyboardTypeDefault;
        _roomTF.attributedPlaceholder = [@"请输入" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#909399"]} range:NSMakeRange(0, 3)];
        _roomTF.font = LGFont(15);
    }
    return _roomTF;
}


-(UIButton *)leftButton{
    if(!_leftButton){
        _leftButton = [UIButton buttonWithTitle:@"删除" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#429BFF" imageName:@""];
        _leftButton.frame = CGRectMake(viewPix(16), Screen_H-topBarHeight-viewPix(65)-bottomSafeBarHeight/4.0, (Screen_W-viewPix(44))/2.0, viewPix(46));
        _leftButton.layer.borderColor = [UIColor colorWithString:@"#429BFF"].CGColor;
        _leftButton.layer.borderWidth = 1;
        _leftButton.backgroundColor = [UIColor whiteColor];
        _leftButton.cornerRidus = 10;
        [_leftButton addTarget:self action:@selector(leftButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftButton;
}

-(UIButton *)sureButton{
    if(!_sureButton){
        _sureButton = [UIButton buttonWithTitle:@"确定" topMargin:kMinY(self.leftButton.frame)];
        _sureButton.frame = CGRectMake(viewPix(16), kMinY(self.leftButton.frame), Screen_W-viewPix(32), viewPix(46));
        [_sureButton addTarget:self action:@selector(sureButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureButton;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
